package com.deyuanyun.pic.ctrl.controller.vo.exinsp;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.format.DateFormat;
import com.deyuanyun.pic.ctrl.domain.EqptCptestStation;
import com.deyuanyun.pic.ctrl.domain.ExinspPipeCorsTest;
import com.deyuanyun.pic.ctrl.enumeration.AbnormalEnum;
import com.deyuanyun.pic.ctrl.enumeration.CathodicProtectionEvaluationEnum;
import com.deyuanyun.pic.ctrl.enumeration.EvalAntiCorrLayerEnum;
import com.deyuanyun.pic.ctrl.service.EQPTBaseService;
import com.deyuanyun.pic.pipe.controller.vo.BaseVOUtil;
import com.deyuanyun.pic.settings.support.biz.PipeLineUtil;
import com.github.pagehelper.Page;

import java.math.BigDecimal;

/**
 * 管道穿越段测试记录表
 */
public class ExinspPipeCorsTestVO extends ExinspBaseVO<ExinspPipeCorsTest> {

    // 管道编号
    private String pipeLineName;
    // 穿越段名称
    private String crossingName;
    // 上游测试桩编号
    private String upStationNumber;
    // 下游测试桩编号
    private String downStationNumber;
    // 位置描述
    private String locationDescription;
    // 断电电位(mV)_上游
    public Long upStreamPotential;
    // 断电电位(mV)_下游
    public Long downStreamPotential;
    // 防腐层绝缘电阻（Ω·m2）
    private BigDecimal antiCorrLayerInsuResis;
    // 防腐层评价（优、良、一般、差）
    private String evalOfAntiCorrLayer;
    // 阴保有效性评价（有效保护、欠保护、过保护）
    private String cathodicProtectionEvaluation;
    // 异常记录
    private String faultRecord;
    // 是否有异常(YES、NO、UNKNOWN)
    private String abnormal;
    // 处理措施
    private String treatmentMeasures;
    // 检测日期
    private String testingDate;
    // 检测单位
    private String testingCompany;

    public String getPipeLineName() {
        return pipeLineName;
    }

    public void setPipeLineName(String pipeLineName) {
        this.pipeLineName = pipeLineName;
    }

    public String getCrossingName() {
        return crossingName;
    }

    public void setCrossingName(String crossingName) {
        this.crossingName = crossingName;
    }

    public String getUpStationNumber() {
        return upStationNumber;
    }

    public void setUpStationNumber(String upStationNumber) {
        this.upStationNumber = upStationNumber;
    }

    public String getDownStationNumber() {
        return downStationNumber;
    }

    public void setDownStationNumber(String downStationNumber) {
        this.downStationNumber = downStationNumber;
    }

    public String getLocationDescription() {
        return locationDescription;
    }

    public void setLocationDescription(String locationDescription) {
        this.locationDescription = locationDescription;
    }

    public Long getUpStreamPotential() {
        return upStreamPotential;
    }

    public void setUpStreamPotential(Long upStreamPotential) {
        this.upStreamPotential = upStreamPotential;
    }

    public Long getDownStreamPotential() {
        return downStreamPotential;
    }

    public void setDownStreamPotential(Long downStreamPotential) {
        this.downStreamPotential = downStreamPotential;
    }

    public BigDecimal getAntiCorrLayerInsuResis() {
        return antiCorrLayerInsuResis;
    }

    public void setAntiCorrLayerInsuResis(BigDecimal antiCorrLayerInsuResis) {
        this.antiCorrLayerInsuResis = antiCorrLayerInsuResis;
    }

    public String getEvalOfAntiCorrLayer() {
        return evalOfAntiCorrLayer;
    }

    public void setEvalOfAntiCorrLayer(String evalOfAntiCorrLayer) {
        this.evalOfAntiCorrLayer = evalOfAntiCorrLayer;
    }

    public String getCathodicProtectionEvaluation() {
        return cathodicProtectionEvaluation;
    }

    public void setCathodicProtectionEvaluation(String cathodicProtectionEvaluation) {
        this.cathodicProtectionEvaluation = cathodicProtectionEvaluation;
    }

    public String getAbnormal() {
        return abnormal;
    }

    public void setAbnormal(String abnormal) {
        this.abnormal = abnormal;
    }

    public String getFaultRecord() {
        return faultRecord;
    }

    public void setFaultRecord(String faultRecord) {
        this.faultRecord = faultRecord;
    }

    public String getTreatmentMeasures() {
        return treatmentMeasures;
    }

    public void setTreatmentMeasures(String treatmentMeasures) {
        this.treatmentMeasures = treatmentMeasures;
    }

    public String getTestingDate() {
        return testingDate;
    }

    public void setTestingDate(String testingDate) {
        this.testingDate = testingDate;
    }

    public String getTestingCompany() {
        return testingCompany;
    }

    public void setTestingCompany(String testingCompany) {
        this.testingCompany = testingCompany;
    }

    EQPTBaseService eqptBaseService = SpringAppliction.getBean(EQPTBaseService.class);

    public void fromDomain(ExinspPipeCorsTest domain) {

        // 管道名称
        this.pipeLineName = PipeLineUtil.getPipeLineName(domain.getPipeLineId());
        // 穿越段名称
        this.crossingName = domain.getCrossingName();
        // 上游测试桩编号
        EqptCptestStation eqptCptestStation = eqptBaseService.queryObjectByPrimaryKey(EqptCptestStation.class, domain.getUpStationNumber());
        this.upStationNumber = eqptCptestStation==null ? null : eqptCptestStation.getCustomNumber();
        // 下游测试桩编号
        EqptCptestStation downEqptCptestStation = eqptBaseService.queryObjectByPrimaryKey(EqptCptestStation.class, domain.getDownStationNumber());
        this.downStationNumber = downEqptCptestStation==null ? null : downEqptCptestStation.getCustomNumber();
        // 位置描述
        this.locationDescription = domain.getLocationDescription();
        // 断电电位(mV)_上游
        this.upStreamPotential = domain.getUpStreamPotential();
        // 断电电位(mV)_下游
        this.downStreamPotential = domain.getDownStreamPotential();
        // 防腐层绝缘电阻（Ω·m2）
        this.antiCorrLayerInsuResis = domain.getAntiCorrLayerInsuResis();
        // 防腐层评价（优、良、一般、差）
        this.evalOfAntiCorrLayer = EvalAntiCorrLayerEnum.getLabel(domain.getEvalOfAntiCorrLayer());
        // 阴保有效性评价（有效保护、欠保护、过保护）
        this.cathodicProtectionEvaluation = CathodicProtectionEvaluationEnum.getLabel(domain.getCathodicProtectionEvaluation());
        // 异常记录
        this.faultRecord = domain.getFaultRecord();
        // 是否有异常(YES、NO、UNKNOWN)
        this.abnormal = AbnormalEnum.getLabel(domain.getAbnormal());
        // 处理措施
        this.treatmentMeasures = domain.getUpdateRemark();;
        // 检测日期
        this.testingDate = DateFormat.format(domain.getTestingDate());
        // 检测单位
        this.testingCompany = domain.getTestingCompany();

        super.fromDomain(domain.getId(), domain.getRecorder(), domain.getRecordTime(), domain.getRemarks());
    }

    public Page<ExinspPipeCorsTestVO> fromDomainList(Page<ExinspPipeCorsTest> domainList) {

        Page<ExinspPipeCorsTestVO> list = new Page<ExinspPipeCorsTestVO>();
        for (ExinspPipeCorsTest exinspPipeCorsTest : domainList) {
            ExinspPipeCorsTestVO exinspPipeCorsTestVO = new ExinspPipeCorsTestVO();
            exinspPipeCorsTestVO.fromDomain(exinspPipeCorsTest);
            list.add(exinspPipeCorsTestVO);
        }
        BaseVOUtil.converterPage(domainList, list);
        return list;
    }

}